package com.cskaoyan.javase._1extends._5protected.clone;

/**
 * Java所有类都直接或间接地继承了Object
 * 也会同时继承它当中的一个protected修饰的成员方法clone()
 * Object类处在java.lang包下
 * 它的clone方法也属于这个包下
 *
 * @since 11:31
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student s = new Student();
        // s能不能调用clone方法呢?
        // Demo类是Object的子类,在这里,只能创建子类自身Demo类对象,才能够访问父类中的受保护成员
        // 'clone()' has protected access in 'java.lang.Object'
        // s.clone();

        Teacher t = new Teacher();
        // t能不能调用clone方法呢?
        t.clone();
    }
}

class Teacher {
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Student {
    public void test() throws CloneNotSupportedException {
        // Unhandled exception: java.lang.CloneNotSupportedException
        clone();
    }

    public static void testStatic() throws CloneNotSupportedException {
        Demo d = new Demo();
        // d.clone();
        Student s = new Student();
        s.clone();
    }
}